package com.leyou.upload.service;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Service;
import org.springframework.web.multipart.MultipartFile;


import javax.imageio.ImageIO;
import java.awt.image.BufferedImage;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Set;


@Service
public class UploadService {

    Logger logger = LoggerFactory.getLogger(UploadService.class);

    public String uploadImage(MultipartFile file) {
        //创建允许保存的文件图片后缀的集合
        Set<String>  allowExt = new HashSet<>();
        allowExt.add("image/png");
        allowExt.add("image/jpg");
        allowExt.add("image/jpeg");

        //判断文件的后缀  相当于判断文件的类型   8+3规范
        String contentType = file.getContentType();

        if (!allowExt.contains(contentType)){
            logger.info("您上传的图片有误，只能上传png、jpg和jpeg后缀的图片，请重新上传");
            return  null;
        }

        //判断文件的内容



        //IO保存文件


        System.out.println("file="+file);
        return  null;
    }
}
